package util;

import org.apache.commons.codec.digest.DigestUtils;
import weixinpay.WeiXinPay;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;

import static http_post.src.util.StringUtil.byteArrayToHexString;

/**
 * Created by Administrator on 2017/2/15 0015.
 */
public class text {

    public static void main(String[] args) throws UnsupportedEncodingException {
        /*text text = new text();
        String md5="appId=wx079bba8222507669&nonceStr=15ca205cb8c2400bbc36120abe7a2f1e&package='prepay_id=wx201702151334121b36abbc860281118905'&signType=MD5&timeStamp=1487136852&key=ZC6EGWXA2DXO2OYWWAWKKWQ729GLSYXE";
        text.getMD5(md5);
        String resultString = null;
        try {
            resultString = md5;
            MessageDigest md = MessageDigest.getInstance("MD5");
            resultString = byteArrayToHexString(md.digest(resultString.getBytes("utf-8")));//正确的写法
            System.out.print(resultString);
        } catch (Exception e) {
            e.printStackTrace();
        }*/
        String name=",1487747019229";
        System.out.print(name.substring(1,name.length()));
       /* Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateNowStr = sdf.format(d);
        System.out.print(dateNowStr);*/
    }
    /**
     * MD5加密
     * @param message 要进行MD5加密的字符串
     * @return 加密结果为32位字符串
     */
    public static String getMD5(String message) {
        MessageDigest messageDigest = null;
        StringBuffer md5StrBuff = new StringBuffer();
        try {
            messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.reset();
            messageDigest.update(message.getBytes("UTF-8"));

            byte[] byteArray = messageDigest.digest();
            for (int i = 0; i < byteArray.length; i++)
            {
                if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
                    md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
                else
                    md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
            }
        } catch (Exception e) {
            throw new RuntimeException();
        }
        //System.out.print(md5StrBuff.toString().toUpperCase());
        return md5StrBuff.toString().toUpperCase();//字母大写
    }
}
